* Generate import shares for inputs and final goods from WIOD
use "WIOD/input/wiot_full.dta", clear
gen U=0 if col_item<=35
replace U=1 if col_item==37 // final consumption expenditure by households
replace U=2 if col_item==41 // gross fixed capital formation
replace U=3 if col_item==38 // final consumption expenditure by non-profits serving households
replace U=4 if col_item==39 // final consumption expenditure by government
replace U=5 if col_item==42 // changes in inventories and valuables
drop if row_item>35 // restrict to the 35 sectors
collapse (sum) value, by (year row_country col_country U) // sum across industries
bys year col_country U: egen totalimports = total(value)
keep if row_country==col_country
gen domshare = value / totalimports 
drop col_country
rename row_country ccode
order ccode, first
sort ccode year U
gen importshare = 1 - domshare
sort U ccode year
drop value totalimports domshare // Reshape to the country-year level
reshape wide importshare, i(ccode year) j(U)
rename importshare0 importshare
rename importshare1 importshareC
sort ccode year
drop importshare2 importshare3 importshare4 importshare5
save "WIOD/output/importsharesWIOD.dta", replace
